def pr(z):
    c = 0
    for i in range(2,z):
        if z % i == 0:
            c += 1
    if c == 0: return True
    else: return False
    
    


digital = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
s = input().split()
if len(s) == 3 and s[0] in digital and s[1] in digital and s[2] in digital and s[0] != 'zero':
    a = digital.index(s[0])
    b = digital.index(s[1])
    c = digital.index(s[2])
    x = a*100 + b*10 + c
    for y in range (x, 1, -1):
        if pr(y)== True:
            q = y
            break
    for v in range(x,1500):
        if pr(v) == True:
            w = v
            break
else:
    print('Wrong input')
if (x - q) < (w - x):
    print(q)
else:
    print(w)
